package com.guigu.www.cxk.controller;

import com.guigu.www.cxk.service.CXKBespeakService;
import com.guigu.www.pojo.Bespeak;
import com.guigu.www.pojo.SingleDayAppointment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;

//体检预约表 预约单设计表
@Controller
@RequestMapping("/ProBeak")
public class CXKBespeakController {
    @Autowired
    CXKBespeakService bespeakService;

    @PostMapping("{time}")
    @ResponseBody
    public int SaveBespeak(@RequestBody Bespeak bespeak, @PathVariable String time) throws ParseException {
        // 修改预约单可预约人数
        int i = bespeakService.UpdateSingle(1, time);
        bespeak.setBesTime(time);
        // 添加添加人信息
        int savebespeak = bespeakService.Savebespeak(bespeak);
        return savebespeak;
    }

    /*根据会员id查询体验预约信息*/
    @PostMapping("selecttaocan/{sid}")
    @ResponseBody
    public List<Bespeak> selecttaocan(@PathVariable int sid){
        return bespeakService.selectbeskpeak(sid);
    }

    /*根据会员id修改预约状态*/
    @PostMapping("updatestate/{besname}/{bestime}")
    @ResponseBody
    public int updatestate(@PathVariable String besname,@PathVariable String bestime){
        SingleDayAppointment singleDayAppointment = bespeakService.selectByDate(bestime);
        if(singleDayAppointment.getSinDayAppApp()!=0){
            bespeakService.UpdateBesk(1,bestime);
            return bespeakService.updateByMid(3,besname);
        }else{
            return 1;
        }
    }
}
